package com.vmladenov.cook.core.converters;

import android.database.Cursor;

import com.vmladenov.cook.core.GlobalStrings;
import com.vmladenov.cook.core.html.SmallPreview;

public class RecipeSmallViewConverter implements ICursorConverter<SmallPreview>
{
	public RecipeSmallViewConverter()
	{
	}

	@Override
	public SmallPreview Convert(Cursor cursor)
	{
		SmallPreview preview = new SmallPreview();

		preview.setId(cursor.getLong(0));
		preview.setTitle(cursor.getString(4)); // Title
		preview.setDescription(cursor.getString(8)); // Date
		preview.setBigViewUrl(cursor.getString(2)); // URL
		// preview.setIsFavorite(!cursor.isNull(9));
		String imageUrl = cursor.getString(3);
		if (imageUrl != null)
		{
			String imageName = imageUrl.substring(imageUrl.lastIndexOf('/') + 1);
			String smallImageUrl = GlobalStrings.RecipeImagesUrlPrefix
					+ GlobalStrings.SmallImage60UrlPrefix + imageName;
			preview.setImageUrl(smallImageUrl);
			// try
			// {
			// preview.setCachedImage(Helpers.getSmallRecipeImage(context,
			// imageName));
			// }
			// catch (IOException e)
			// {
			// e.printStackTrace();
			// }
		}

		return preview;
	}

}
